options compress=YES;
libname manasi ''; 
libname f831 ''; 

* MERGE PARENTAL DI RECEIPT INTO CHILDRENS' RECORDS;

* USE ONLY HUN AND PAN FROM PARENTS' SSR RECORDS;
data manasi.ssr_parents_hunpan;
	set manasi.ssr_parents_full(keep=hun pan toa mft dob dobyy dod sex);
	if pan='*00000000' then delete;
run;

* ELIMINATE DUPLICATES BY HUN AND PAN AND SORT ;
proc sort data=manasi.ssr_parents_hunpan out=manasi.ssr_parents_hunpan nodupkey;
	by pan hun;
run;


* SORT PARENT MBR RECORDS ;
proc sort data=manasi.par_mbr_prep2 out=manasi.par_mbr_prep2;
	by ssn;
run;

* MERGE IN PARENT MBR RECORDS ;
data manasi.par_mbr_hunmerge;
	merge 	
			manasi.ssr_parents_hunpan 
			(rename=(pan=ssn dob=dob_ssr dobyy=dobyy_ssr sex=sex_ssr toa=toa_ssr mft=mft_ssr dod=dod_ssr) 
				in=fromssrx)

			manasi.par_mbr_prep2 
			(keep=ssn n_dimbayr_: /* n_dimbpyr_: */ n_diindyr_: in=fromparmbrx);

	by ssn; 
	fromssr = fromssrx;
	fromparmbr = fromparmbrx;
run;

proc tabulate data=manasi.par_mbr_hunmerge;
	class fromparmbr fromssr;
	table fromparmbr, fromssr;
run;

* MERGE IN VARIABLE INDICATING WHETHER PARENT WAS IN HOUSEHOLD AT ANY TIME
BETWEEN 2002 AND 2006 (GENERAL TREATMENT PERIOD);
proc sort data=manasi.par_mbr_hunmerge out=manasi.par_mbr_hunmerge;
	by hun ssn;
run;

data manasi.par_mbr_hunmerge;
	merge 	
			manasi.par_mbr_hunmerge 

			manasi.ssr_parents_estpdonly_wide
			(rename=(pan=ssn) keep=hun pan inhh0206);

	by hun ssn; 
run;

proc sort data=manasi.par_mbr_hunmerge out=manasi.par_mbr_hunmerge;
	by hun;
run;

data manasi.par_mbr_hunmerge_wide;
	set manasi.par_mbr_hunmerge;
	par_id + 1;
	by hun;
	if first.hun then par_id=1;
run;

data manasi.par_mbr_hunmerge_wide;
	set manasi.par_mbr_hunmerge_wide;
	if ssn='*00000000' then delete;
run;

* SEE HOW MANY PARENTS SSI KIDS HAVE ;
proc means data=manasi.par_mbr_hunmerge_wide noprint;
	by hun;
	var par_id;
	output out=manasi.par_mbr_parid max(par_id)=max_parid;
run;

proc means mean median min max p90 p95 p99 data=manasi.par_mbr_parid;
	var max_parid;
run;

* COLLAPSE TO HUN LEVEL TO GET ONE RECORD FOR EACH KID;
data manasi.par_mbr_hunmerge_wide;
	set manasi.par_mbr_hunmerge_wide;
	by hun;

	keep 	hun 
			ssn1-ssn7 
			toa_ssr1-toa_ssr7 
			mft_ssr1-mft_ssr7
			dob_ssr1-dob_ssr7
			dobyy_ssr1-dobyy_ssr7 
			dod_ssr1-dod_ssr7 
			sex_ssr1-sex_ssr7

			inhh0206_1-inhh0206_7
			n_dimbayr_1985_1-n_dimbayr_1985_7
			n_dimbayr_1986_1-n_dimbayr_1986_7
			n_dimbayr_1987_1-n_dimbayr_1987_7
			n_dimbayr_1988_1-n_dimbayr_1988_7
			n_dimbayr_1989_1-n_dimbayr_1989_7
			n_dimbayr_1990_1-n_dimbayr_1990_7
			n_dimbayr_1991_1-n_dimbayr_1991_7
			n_dimbayr_1992_1-n_dimbayr_1992_7
			n_dimbayr_1993_1-n_dimbayr_1993_7
			n_dimbayr_1994_1-n_dimbayr_1994_7
			n_dimbayr_1995_1-n_dimbayr_1995_7
			n_dimbayr_1996_1-n_dimbayr_1996_7
			n_dimbayr_1997_1-n_dimbayr_1997_7
			n_dimbayr_1998_1-n_dimbayr_1998_7
			n_dimbayr_1999_1-n_dimbayr_1999_7
			n_dimbayr_2000_1-n_dimbayr_2000_7
			n_dimbayr_2001_1-n_dimbayr_2001_7
			n_dimbayr_2002_1-n_dimbayr_2002_7
			n_dimbayr_2003_1-n_dimbayr_2003_7
			n_dimbayr_2004_1-n_dimbayr_2004_7
			n_dimbayr_2005_1-n_dimbayr_2005_7
			n_dimbayr_2006_1-n_dimbayr_2006_7
			n_dimbayr_2007_1-n_dimbayr_2007_7
			n_dimbayr_2008_1-n_dimbayr_2008_7
			n_dimbayr_2009_1-n_dimbayr_2009_7
			n_dimbayr_2010_1-n_dimbayr_2010_7
			n_dimbayr_2011_1-n_dimbayr_2011_7

			n_diindyr_1985_1-n_diindyr_1985_7
			n_diindyr_1986_1-n_diindyr_1986_7
			n_diindyr_1987_1-n_diindyr_1987_7
			n_diindyr_1988_1-n_diindyr_1988_7
			n_diindyr_1989_1-n_diindyr_1989_7
			n_diindyr_1990_1-n_diindyr_1990_7
			n_diindyr_1991_1-n_diindyr_1991_7
			n_diindyr_1992_1-n_diindyr_1992_7
			n_diindyr_1993_1-n_diindyr_1993_7
			n_diindyr_1994_1-n_diindyr_1994_7
			n_diindyr_1995_1-n_diindyr_1995_7
			n_diindyr_1996_1-n_diindyr_1996_7
			n_diindyr_1997_1-n_diindyr_1997_7
			n_diindyr_1998_1-n_diindyr_1998_7
			n_diindyr_1999_1-n_diindyr_1999_7
			n_diindyr_2000_1-n_diindyr_2000_7
			n_diindyr_2001_1-n_diindyr_2001_7
			n_diindyr_2002_1-n_diindyr_2002_7
			n_diindyr_2003_1-n_diindyr_2003_7
			n_diindyr_2004_1-n_diindyr_2004_7
			n_diindyr_2005_1-n_diindyr_2005_7
			n_diindyr_2006_1-n_diindyr_2006_7
			n_diindyr_2007_1-n_diindyr_2007_7
			n_diindyr_2008_1-n_diindyr_2008_7
			n_diindyr_2009_1-n_diindyr_2009_7
			n_diindyr_2010_1-n_diindyr_2010_7
			n_diindyr_2011_1-n_diindyr_2011_7
			;
			

	retain 	 
			ssn1-ssn7 
			toa_ssr1-toa_ssr7 
			mft_ssr1-mft_ssr7
			dob_ssr1-dob_ssr7
			dobyy_ssr1-dobyy_ssr7 
			dod_ssr1-dod_ssr7 
			sex_ssr1-sex_ssr7

			inhh0206_1-inhh0206_7
			n_dimbayr_1985_1-n_dimbayr_1985_7
			n_dimbayr_1986_1-n_dimbayr_1986_7
			n_dimbayr_1987_1-n_dimbayr_1987_7
			n_dimbayr_1988_1-n_dimbayr_1988_7
			n_dimbayr_1989_1-n_dimbayr_1989_7
			n_dimbayr_1990_1-n_dimbayr_1990_7
			n_dimbayr_1991_1-n_dimbayr_1991_7
			n_dimbayr_1992_1-n_dimbayr_1992_7
			n_dimbayr_1993_1-n_dimbayr_1993_7
			n_dimbayr_1994_1-n_dimbayr_1994_7
			n_dimbayr_1995_1-n_dimbayr_1995_7
			n_dimbayr_1996_1-n_dimbayr_1996_7
			n_dimbayr_1997_1-n_dimbayr_1997_7
			n_dimbayr_1998_1-n_dimbayr_1998_7
			n_dimbayr_1999_1-n_dimbayr_1999_7
			n_dimbayr_2000_1-n_dimbayr_2000_7
			n_dimbayr_2001_1-n_dimbayr_2001_7
			n_dimbayr_2002_1-n_dimbayr_2002_7
			n_dimbayr_2003_1-n_dimbayr_2003_7
			n_dimbayr_2004_1-n_dimbayr_2004_7
			n_dimbayr_2005_1-n_dimbayr_2005_7
			n_dimbayr_2006_1-n_dimbayr_2006_7
			n_dimbayr_2007_1-n_dimbayr_2007_7
			n_dimbayr_2008_1-n_dimbayr_2008_7
			n_dimbayr_2009_1-n_dimbayr_2009_7
			n_dimbayr_2010_1-n_dimbayr_2010_7
			n_dimbayr_2011_1-n_dimbayr_2011_7

			n_diindyr_1985_1-n_diindyr_1985_7
			n_diindyr_1986_1-n_diindyr_1986_7
			n_diindyr_1987_1-n_diindyr_1987_7
			n_diindyr_1988_1-n_diindyr_1988_7
			n_diindyr_1989_1-n_diindyr_1989_7
			n_diindyr_1990_1-n_diindyr_1990_7
			n_diindyr_1991_1-n_diindyr_1991_7
			n_diindyr_1992_1-n_diindyr_1992_7
			n_diindyr_1993_1-n_diindyr_1993_7
			n_diindyr_1994_1-n_diindyr_1994_7
			n_diindyr_1995_1-n_diindyr_1995_7
			n_diindyr_1996_1-n_diindyr_1996_7
			n_diindyr_1997_1-n_diindyr_1997_7
			n_diindyr_1998_1-n_diindyr_1998_7
			n_diindyr_1999_1-n_diindyr_1999_7
			n_diindyr_2000_1-n_diindyr_2000_7
			n_diindyr_2001_1-n_diindyr_2001_7
			n_diindyr_2002_1-n_diindyr_2002_7
			n_diindyr_2003_1-n_diindyr_2003_7
			n_diindyr_2004_1-n_diindyr_2004_7
			n_diindyr_2005_1-n_diindyr_2005_7
			n_diindyr_2006_1-n_diindyr_2006_7
			n_diindyr_2007_1-n_diindyr_2007_7
			n_diindyr_2008_1-n_diindyr_2008_7
			n_diindyr_2009_1-n_diindyr_2009_7
			n_diindyr_2010_1-n_diindyr_2010_7
			n_diindyr_2011_1-n_diindyr_2011_7
			;

	array	assn(1:7) 			ssn1-ssn7 ; 
	array	atoa_ssr(1:7) $ 2	toa_ssr1-toa_ssr7 ;
	array	amft_ssr(1:7) $ 2	mft_ssr1-mft_ssr7;
	array	adob_ssr(1:7)		dob_ssr1-dob_ssr7;
	array	adobyy_ssr(1:7)		dobyy_ssr1-dobyy_ssr7; 
	array	adod_ssr(1:7)		dod_ssr1-dod_ssr7 ;
	array	asex_ssr(1:7) $ 2	sex_ssr1-sex_ssr7;

	array 	ainhh0206(1:7)		inhh0206_1-inhh0206_7;
	array 	adimbayr_1985(1:7) 	n_dimbayr_1985_1-n_dimbayr_1985_7;
	array 	adimbayr_1986(1:7) 	n_dimbayr_1986_1-n_dimbayr_1986_7;
	array 	adimbayr_1987(1:7) 	n_dimbayr_1987_1-n_dimbayr_1987_7;
	array 	adimbayr_1988(1:7) 	n_dimbayr_1988_1-n_dimbayr_1988_7;
	array 	adimbayr_1989(1:7) 	n_dimbayr_1989_1-n_dimbayr_1989_7;
	array 	adimbayr_1990(1:7) 	n_dimbayr_1990_1-n_dimbayr_1990_7;
	array 	adimbayr_1991(1:7) 	n_dimbayr_1991_1-n_dimbayr_1991_7;
	array 	adimbayr_1992(1:7) 	n_dimbayr_1992_1-n_dimbayr_1992_7;
	array 	adimbayr_1993(1:7) 	n_dimbayr_1993_1-n_dimbayr_1993_7;
	array 	adimbayr_1994(1:7) 	n_dimbayr_1994_1-n_dimbayr_1994_7;
	array 	adimbayr_1995(1:7) 	n_dimbayr_1995_1-n_dimbayr_1995_7;
	array 	adimbayr_1996(1:7) 	n_dimbayr_1996_1-n_dimbayr_1996_7;
	array 	adimbayr_1997(1:7) 	n_dimbayr_1997_1-n_dimbayr_1997_7;
	array 	adimbayr_1998(1:7) 	n_dimbayr_1998_1-n_dimbayr_1998_7;
	array 	adimbayr_1999(1:7) 	n_dimbayr_1999_1-n_dimbayr_1999_7;
	array 	adimbayr_2000(1:7) 	n_dimbayr_2000_1-n_dimbayr_2000_7;
	array 	adimbayr_2001(1:7) 	n_dimbayr_2001_1-n_dimbayr_2001_7;
	array 	adimbayr_2002(1:7) 	n_dimbayr_2002_1-n_dimbayr_2002_7;
	array 	adimbayr_2003(1:7) 	n_dimbayr_2003_1-n_dimbayr_2003_7;
	array 	adimbayr_2004(1:7) 	n_dimbayr_2004_1-n_dimbayr_2004_7;
	array 	adimbayr_2005(1:7) 	n_dimbayr_2005_1-n_dimbayr_2005_7;
	array 	adimbayr_2006(1:7) 	n_dimbayr_2006_1-n_dimbayr_2006_7;
	array 	adimbayr_2007(1:7) 	n_dimbayr_2007_1-n_dimbayr_2007_7;
	array 	adimbayr_2008(1:7) 	n_dimbayr_2008_1-n_dimbayr_2008_7;
	array 	adimbayr_2009(1:7) 	n_dimbayr_2009_1-n_dimbayr_2009_7;
	array 	adimbayr_2010(1:7) 	n_dimbayr_2010_1-n_dimbayr_2010_7;
	array 	adimbayr_2011(1:7) 	n_dimbayr_2011_1-n_dimbayr_2011_7;

	array 	adiindyr_1985(1:7) 	n_diindyr_1985_1-n_diindyr_1985_7;
	array 	adiindyr_1986(1:7) 	n_diindyr_1986_1-n_diindyr_1986_7;
	array 	adiindyr_1987(1:7) 	n_diindyr_1987_1-n_diindyr_1987_7;
	array 	adiindyr_1988(1:7) 	n_diindyr_1988_1-n_diindyr_1988_7;
	array 	adiindyr_1989(1:7) 	n_diindyr_1989_1-n_diindyr_1989_7;
	array 	adiindyr_1990(1:7) 	n_diindyr_1990_1-n_diindyr_1990_7;
	array 	adiindyr_1991(1:7) 	n_diindyr_1991_1-n_diindyr_1991_7;
	array 	adiindyr_1992(1:7) 	n_diindyr_1992_1-n_diindyr_1992_7;
	array 	adiindyr_1993(1:7) 	n_diindyr_1993_1-n_diindyr_1993_7;
	array 	adiindyr_1994(1:7) 	n_diindyr_1994_1-n_diindyr_1994_7;
	array 	adiindyr_1995(1:7) 	n_diindyr_1995_1-n_diindyr_1995_7;
	array 	adiindyr_1996(1:7) 	n_diindyr_1996_1-n_diindyr_1996_7;
	array 	adiindyr_1997(1:7) 	n_diindyr_1997_1-n_diindyr_1997_7;
	array 	adiindyr_1998(1:7) 	n_diindyr_1998_1-n_diindyr_1998_7;
	array 	adiindyr_1999(1:7) 	n_diindyr_1999_1-n_diindyr_1999_7;
	array 	adiindyr_2000(1:7) 	n_diindyr_2000_1-n_diindyr_2000_7;
	array 	adiindyr_2001(1:7) 	n_diindyr_2001_1-n_diindyr_2001_7;
	array 	adiindyr_2002(1:7) 	n_diindyr_2002_1-n_diindyr_2002_7;
	array 	adiindyr_2003(1:7) 	n_diindyr_2003_1-n_diindyr_2003_7;
	array 	adiindyr_2004(1:7) 	n_diindyr_2004_1-n_diindyr_2004_7;
	array 	adiindyr_2005(1:7) 	n_diindyr_2005_1-n_diindyr_2005_7;
	array 	adiindyr_2006(1:7) 	n_diindyr_2006_1-n_diindyr_2006_7;
	array 	adiindyr_2007(1:7) 	n_diindyr_2007_1-n_diindyr_2007_7;
	array 	adiindyr_2008(1:7) 	n_diindyr_2008_1-n_diindyr_2008_7;
	array 	adiindyr_2009(1:7) 	n_diindyr_2009_1-n_diindyr_2009_7;
	array 	adiindyr_2010(1:7) 	n_diindyr_2010_1-n_diindyr_2010_7;
	array 	adiindyr_2011(1:7) 	n_diindyr_2011_1-n_diindyr_2011_7;

	if first.hun then
	do;
		do i=1 to 7;
			assn(i) 		=.;	
			atoa_ssr(i)		="";
			amft_ssr(i)		="";	
			adob_ssr(i)		=.;	
			adobyy_ssr(i)	=.;		
			adod_ssr(i)		=.;	
			asex_ssr(i)		="";

			ainhh0206(i)		=.;
			adimbayr_1985(i)	=.;
			adimbayr_1986(i)	=.;
			adimbayr_1987(i)	=.;
			adimbayr_1988(i)	=.;
			adimbayr_1989(i)	=.;
			adimbayr_1990(i)	=.;
			adimbayr_1991(i)	=.;
			adimbayr_1992(i)	=.;
			adimbayr_1993(i)	=.;
			adimbayr_1994(i)	=.;
			adimbayr_1995(i)	=.;
			adimbayr_1996(i)	=.;
			adimbayr_1997(i)	=.;
			adimbayr_1998(i)	=.;
			adimbayr_1999(i)	=.;
			adimbayr_2000(i)	=.;
			adimbayr_2001(i)	=.;
			adimbayr_2002(i)	=.;
			adimbayr_2003(i)	=.;
			adimbayr_2004(i)	=.;
			adimbayr_2005(i)	=.;
			adimbayr_2006(i)	=.;
			adimbayr_2007(i)	=.;
			adimbayr_2008(i)	=.;
			adimbayr_2009(i)	=.;
			adimbayr_2010(i)	=.;
			adimbayr_2011(i)	=.;

			adiindyr_1985(i)	=.;
			adiindyr_1986(i)	=.;
			adiindyr_1987(i)	=.;
			adiindyr_1988(i)	=.;
			adiindyr_1989(i)	=.;
			adiindyr_1990(i)	=.;
			adiindyr_1991(i)	=.;
			adiindyr_1992(i)	=.;
			adiindyr_1993(i)	=.;
			adiindyr_1994(i)	=.;
			adiindyr_1995(i)	=.;
			adiindyr_1996(i)	=.;
			adiindyr_1997(i)	=.;
			adiindyr_1998(i)	=.;
			adiindyr_1999(i)	=.;
			adiindyr_2000(i)	=.;
			adiindyr_2001(i)	=.;
			adiindyr_2002(i)	=.;
			adiindyr_2003(i)	=.;
			adiindyr_2004(i)	=.;
			adiindyr_2005(i)	=.;
			adiindyr_2006(i)	=.;
			adiindyr_2007(i)	=.;
			adiindyr_2008(i)	=.;
			adiindyr_2009(i)	=.;
			adiindyr_2010(i)	=.;
			adiindyr_2011(i)	=.;
		end;
	end;

	assn(par_id) 		= ssn ;	
	atoa_ssr(par_id)	= toa_ssr ;
	amft_ssr(par_id)	= mft_ssr ;	
	adob_ssr(par_id)	= dob_ssr ;	
	adobyy_ssr(par_id)	= dobyy_ssr ;		
	adod_ssr(par_id)	= dod_ssr ;	
	asex_ssr(par_id)	= sex_ssr;
	
	ainhh0206(par_id)		= inhh0206;
	adimbayr_1985(par_id)	= n_dimbayr_1985;
	adimbayr_1986(par_id)	= n_dimbayr_1986;
	adimbayr_1987(par_id)	= n_dimbayr_1987;
	adimbayr_1988(par_id)	= n_dimbayr_1988;
	adimbayr_1989(par_id)	= n_dimbayr_1989;
	adimbayr_1990(par_id)	= n_dimbayr_1990;
	adimbayr_1991(par_id)	= n_dimbayr_1991;
	adimbayr_1992(par_id)	= n_dimbayr_1992;
	adimbayr_1993(par_id)	= n_dimbayr_1993;
	adimbayr_1994(par_id)	= n_dimbayr_1994;
	adimbayr_1995(par_id)	= n_dimbayr_1995;
	adimbayr_1996(par_id)	= n_dimbayr_1996;
	adimbayr_1997(par_id)	= n_dimbayr_1997;
	adimbayr_1998(par_id)	= n_dimbayr_1998;
	adimbayr_1999(par_id)	= n_dimbayr_1999;
	adimbayr_2000(par_id)	= n_dimbayr_2000;
	adimbayr_2001(par_id)	= n_dimbayr_2001;
	adimbayr_2002(par_id)	= n_dimbayr_2002;
	adimbayr_2003(par_id)	= n_dimbayr_2003;
	adimbayr_2004(par_id)	= n_dimbayr_2004;
	adimbayr_2005(par_id)	= n_dimbayr_2005;
	adimbayr_2006(par_id)	= n_dimbayr_2006;
	adimbayr_2007(par_id)	= n_dimbayr_2007;
	adimbayr_2008(par_id)	= n_dimbayr_2008;
	adimbayr_2009(par_id)	= n_dimbayr_2009;
	adimbayr_2010(par_id)	= n_dimbayr_2010;
	adimbayr_2011(par_id)	= n_dimbayr_2011;

	adiindyr_1985(par_id)	= n_diindyr_1985;
	adiindyr_1986(par_id)	= n_diindyr_1986;
	adiindyr_1987(par_id)	= n_diindyr_1987;
	adiindyr_1988(par_id)	= n_diindyr_1988;
	adiindyr_1989(par_id)	= n_diindyr_1989;
	adiindyr_1990(par_id)	= n_diindyr_1990;
	adiindyr_1991(par_id)	= n_diindyr_1991;
	adiindyr_1992(par_id)	= n_diindyr_1992;
	adiindyr_1993(par_id)	= n_diindyr_1993;
	adiindyr_1994(par_id)	= n_diindyr_1994;
	adiindyr_1995(par_id)	= n_diindyr_1995;
	adiindyr_1996(par_id)	= n_diindyr_1996;
	adiindyr_1997(par_id)	= n_diindyr_1997;
	adiindyr_1998(par_id)	= n_diindyr_1998;
	adiindyr_1999(par_id)	= n_diindyr_1999;
	adiindyr_2000(par_id)	= n_diindyr_2000;
	adiindyr_2001(par_id)	= n_diindyr_2001;
	adiindyr_2002(par_id)	= n_diindyr_2002;
	adiindyr_2003(par_id)	= n_diindyr_2003;
	adiindyr_2004(par_id)	= n_diindyr_2004;
	adiindyr_2005(par_id)	= n_diindyr_2005;
	adiindyr_2006(par_id)	= n_diindyr_2006;
	adiindyr_2007(par_id)	= n_diindyr_2007;
	adiindyr_2008(par_id)	= n_diindyr_2008;
	adiindyr_2009(par_id)	= n_diindyr_2009;
	adiindyr_2010(par_id)	= n_diindyr_2010;
	adiindyr_2011(par_id)	= n_diindyr_2011;

	if last.hun then output;

run;

data manasi.par_mbr_hunmerge_wide;
	set manasi.par_mbr_hunmerge_wide;

	* Create macro for summing over all MBR variables;
	%macro summbr(year);
		n_hhmbayr_&year.=SUM(OF n_dimbayr_&year._:);
		n_hhdiindyr_&year.=SUM(OF n_diindyr_&year._:);
		
		n_hhmbayr0206_&year.=0;
		if inhh0206_1=1 then n_hhmbayr0206_&year.=n_hhmbayr0206_&year.+n_dimbayr_&year._1;
		if inhh0206_2=1 then n_hhmbayr0206_&year.=n_hhmbayr0206_&year.+n_dimbayr_&year._2;
		if inhh0206_3=1 then n_hhmbayr0206_&year.=n_hhmbayr0206_&year.+n_dimbayr_&year._3;
		if inhh0206_4=1 then n_hhmbayr0206_&year.=n_hhmbayr0206_&year.+n_dimbayr_&year._4;
		if inhh0206_5=1 then n_hhmbayr0206_&year.=n_hhmbayr0206_&year.+n_dimbayr_&year._5;
		if inhh0206_6=1 then n_hhmbayr0206_&year.=n_hhmbayr0206_&year.+n_dimbayr_&year._6;
		if inhh0206_7=1 then n_hhmbayr0206_&year.=n_hhmbayr0206_&year.+n_dimbayr_&year._7;

		n_hhdiindyr0206_&year.=0;
		if inhh0206_1=1 then n_hhdiindyr0206_&year.=n_hhdiindyr0206_&year.+n_diindyr_&year._1;
		if inhh0206_2=1 then n_hhdiindyr0206_&year.=n_hhdiindyr0206_&year.+n_diindyr_&year._2;
		if inhh0206_3=1 then n_hhdiindyr0206_&year.=n_hhdiindyr0206_&year.+n_diindyr_&year._3;
		if inhh0206_4=1 then n_hhdiindyr0206_&year.=n_hhdiindyr0206_&year.+n_diindyr_&year._4;
		if inhh0206_5=1 then n_hhdiindyr0206_&year.=n_hhdiindyr0206_&year.+n_diindyr_&year._5;
		if inhh0206_6=1 then n_hhdiindyr0206_&year.=n_hhdiindyr0206_&year.+n_diindyr_&year._6;
		if inhh0206_7=1 then n_hhdiindyr0206_&year.=n_hhdiindyr0206_&year.+n_diindyr_&year._7;
	%mend summbr;

	%summbr(1985);
	%summbr(1986);
	%summbr(1987);
	%summbr(1988);
	%summbr(1989);
	%summbr(1990);
	%summbr(1991);
	%summbr(1992);
	%summbr(1993);
	%summbr(1994);
	%summbr(1995);
	%summbr(1996);
	%summbr(1997);
	%summbr(1998);
	%summbr(1999);
	%summbr(2000);
	%summbr(2001);
	%summbr(2002);
	%summbr(2003);
	%summbr(2004);
	%summbr(2005);
	%summbr(2006);
	%summbr(2007);
	%summbr(2008);
	%summbr(2009);
	%summbr(2010);
	%summbr(2011);

	%macro dropvar(var);
		drop &var.3-&var.7;
	%mend dropvar;

	%dropvar(ssn);
	%dropvar(toa_ssr);
	%dropvar(mft_ssr);
	%dropvar(dob_ssr);
	%dropvar(dobyy_ssr);
	%dropvar(dod_ssr);
	%dropvar(sex_ssr);

	%macro dropmbr(year);
		drop n_dimbayr_&year._1-n_dimbayr_&year._7;
		drop n_diindyr_&year._1-n_diindyr_&year._7;
	%mend dropmbr;

	%dropmbr(1985);
	%dropmbr(1986);
	%dropmbr(1987);
	%dropmbr(1988);
	%dropmbr(1989);
	%dropmbr(1990);
	%dropmbr(1991);
	%dropmbr(1992);
	%dropmbr(1993);
	%dropmbr(1994);
	%dropmbr(1995);
	%dropmbr(1996);
	%dropmbr(1997);
	%dropmbr(1998);
	%dropmbr(1999);
	%dropmbr(2000);
	%dropmbr(2001);
	%dropmbr(2002);
	%dropmbr(2003);
	%dropmbr(2004);
	%dropmbr(2005);
	%dropmbr(2006);
	%dropmbr(2007);
	%dropmbr(2008);
	%dropmbr(2009);
	%dropmbr(2010);
	%dropmbr(2011);

	%macro rename(var,no);
		rename &var.&no.=par&no._&var.;
	%mend rename;

	%rename(ssn,1);
	%rename(ssn,2);
	%rename(toa_ssr,1);
	%rename(toa_ssr,2);
	%rename(mft_ssr,1);
	%rename(mft_ssr,2);
	%rename(dob_ssr,1);
	%rename(dob_ssr,2);
	%rename(dobyy_ssr,1);
	%rename(dobyy_ssr,2);
	%rename(dod_ssr,1);
	%rename(dod_ssr,2);
	%rename(sex_ssr,1);
	%rename(sex_ssr,2);

run;
